<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="shortcut icon" href="/favicon.ico"/>
    <link rel="bookmark" href="/favicon.ico"/>
    <title>
        {//标题}
        {block name="title"}{$title}{/block}
    </title>
    {// 引入的css文件}
    {block name="include-css"}
    {include file="common/css"}
    {/block}

    {//自定义css}
    {block name="css"}
    <style>
        .layui-icon {
            font-size: 16px;
        }
        .icon{
            font-size: 20px;
            vertical-align: middle;
        }
        .menu{
            vertical-align: middle;
            margin-left: 5px;
        }
    </style>
    {/block}
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">

    {//头部}
    {block name="header"}
    <div class="layui-header">
        <div class="layui-logo">
            <span class="icon icon-sys" style="font-size: 30px;vertical-align: middle;"></span>
            <span style="font-size: 18px;vertical-align: middle;">合同管理系统</span>
        </div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a href="/">控制台</a></li>
            <li class="layui-nav-item layui-hide">
                <a href="javascript:;">系统设置</a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本设置</a></dd>
                    <dd><a href="">高级设置</a></dd>
                </dl>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <span class="layui-bg-blue layui-nav-img"
                          style="width: 30px;height: 30px; text-align:center;line-height:30px;display:inline-block;border-radius: 50%;vertical-align: middle;">
                        {:mb_substr($Think.session.admin.name, 0, 1, 'UTF-8')}
                    </span>
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img layui-hide">{$Think.session.admin.name}
                </a>
                <dl class="layui-nav-child">
                    <dd>
                        <a href="/user/edit/{$Think.session.admin.id}">
                            <span class="icon icon-profile"></span>
                            <span class="menu">基本资料</span>
                        </a>
                    </dd>
                    <dd>
                        <a href="/user/edit/{$Think.session.admin.id}">
                            <a href="javascript:;">
                                <span class="menu" id="ip">{:mb_substr($Think.session.admin.address,2,6,'utf-8')}</span>
                            </a>
                        </a>
                    </dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="/logout">退出</a></li>
        </ul>
    </div>
    {/block}

    {//左栏}
    {block name="left"}
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item {if $Request.controller=='Contract' && in_array($Request.action, ['add','all','expiring'])}layui-nav-itemed{/if}">
                    <a class="" href="javascript:;">
                        <span class="icon icon-contract"></span>
                        <span class="menu">合同</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="/contract/add">新增合同</a></dd>
                        <dd><a href="/contract/all">全部合同</a></dd>
                        <dd><a href="/contract/expiring">即将到期</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item {if in_array($Request.controller, ['Node', 'Approval'])}layui-nav-itemed{/if}">
                    <a href="javascript:;">
                        <span class="icon icon-flow"></span>
                        <span class="menu">审批</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="/node/approval/{$Think.session.admin.id}">我审批的</a></dd>
                        <dd><a href="/approval/user/{$Think.session.admin.id}">我发起的</a></dd>
                        <dd><a href="/approval/all">全部审批</a></dd>
                        <dd><a href="/approval/add">新建审批</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item {if in_array($Request.controller, ['Customer', 'Linkman'])}layui-nav-itemed{/if}">
                    <a href="javascript:;">
                        <span class="icon icon-customer"></span>
                        <span class="menu">客户</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="/customer/all">客户列表</a></dd>
                        <dd><a href="/linkman/all">联系人列表</a></dd>
                        <dd><a href="/customer/add">新增客户</a></dd>
                        <dd><a href="/linkman/add">新增联系人</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item {if in_array($Request.controller, ['User'])}layui-nav-itemed{/if}">
                    <a href="javascript:;">
                        <span class="icon icon-user"></span>
                        <span class="menu">用户</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="/user/all">用户管理</a></dd>
                        <dd><a href="/user/add">新增用户</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item {if in_array($Request.controller, ['Type', 'Category'])}layui-nav-itemed{/if}">
                    <a href="javascript:;">
                        <span class="icon icon-setting" style="font-size: 19px;"></span>
                        <span class="menu">设置</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="/category/all">合同分类</a></dd>
                        <dd><a href="/category/add">新增合同分类</a></dd>
                        <dd><a href="/type/all">合同类型</a></dd>
                        <dd><a href="/type/add">新增合同类型</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item {if $Request.controller=='Log'}layui-nav-itemed{/if}">
                    <a href="javascript:;">
                        <span class="icon icon-log"></span>
                        <span class="menu">日志</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="/log/contract">合同修改记录</a></dd>
                        <dd><a href="/log/login">用户登录记录</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-hide"><a href="">上传</a></li>
                <li class="layui-nav-item layui-hide"><a href="">其它</a></li>
            </ul>
        </div>
    </div>
    {/block}

    {//主体内容}
    <div class="layui-body">
        <div class="layui-tab" lay-filter="bodyTab">
            <ul class="layui-tab-title">
                <li class="layui-this">
                    {if isset($icon)}{$icon} {/if}
                    {$title}
                </li>
            </ul>
            <div class="layui-tab-content" style="height: 100px;">
                <div class="layui-tab-item layui-show">
                    <div style="padding: 10px;">
                        {block name="content"}
                        <!-- 内容主体区域 -->
                        内容主体区域
                        {/block}
                    </div>
                </div>
            </div>
        </div>
    </div>

    {//底部}
    <div class="layui-footer">
        {block name="footer"}
        <!-- 底部固定区域 -->
        © uniteedu.cn - 联创优学 - 禾瑞技术支持 kf@kvstone.net
        {/block}
    </div>
</div>

{// block other 这里放置其它内容 比如通过DOM调用的layer弹出层content}
{block name="other"}{/block}

{// 包含的js文件}
{block name="include-js"}
{include file="common/js"}
{/block}

{// 自定义的js代码}
{block name="js"}
<script>
    //JavaScript代码区域
    layui.use('element', function () {
        var $ = layui.jquery;
        var element = layui.element;

        //notice
        var noticeFun = function () {
            $.get({
                url: '/notice/pull',
                success: function (result) {
                    console.log(result);
                    if (result.count >= 1) {
                        // 关闭嗅探
                        clearInterval(noticeSniffer);
                        var noticeIds = '';
                        var content = '';
                        for (var i in result.notices) {
                            var item = result.notices[i];
                            noticeIds += ',' + item.id;
                            if (item.approval) {
                                content += '<div class="layui-row">审批 '
                                    + '<a href="javascript:;" class="layui-col notice-item" data-id="' + item.approval.id + '">' + item.approval.name + '</a> '
                                    + item.note
                                    + '</div>';
                            }
                        }
                        noticeIds = noticeIds.replace(/^,*/, '');
                        // 确定与关闭按钮回调
                        var btnFn = function (index, layero) {
                            $.ajax({
                                type: 'DELETE',
                                url: '/notice/del/'+noticeIds,
                                success: function (result) {
                                    console.log(result)
                                },
                                fail: function (error) {
                                    console.log(error)
                                }
                            });
                            // 继续嗅探新通知
                            noticeSniffer = setInterval(noticeFun,5000);
                            layer.close(index);
                        }
                        layer.open({
                            type: 0,
                            shade: 0,
                            offset: 'rb',
                            anim: 2,
                            title: '<span class="layui-icon">&#xe645;</span> 您有新通知',
                            content: content,
                            btn: '知道了',
                            btnAlign: 'c',
                            yes: btnFn,
                            cancel: btnFn
                        });
                        $('.notice-item').click(function () {
                            openNotice($(this).data('id'));
                        });
                    }
                }
            })
        }
        var noticeSniffer = setInterval(noticeFun,5000);
        // 打开审批详情
        var openNotice = function (id) {
            var index = layer.open({
                type: 2,
                title: '<span class="icon icon-flow"></span>  审批详情',
                area: ['500px', '600px'],
                content: '/approval/' + id,
                btn: '确定',
                btnAlign: 'c'
            });
            layer.full(index);
        }
    });
</script>
{/block}
</body>
</html>